C = mpicc
CFLAGS =  -c -g 

INCLUDE = -I./include
LIBPATH = -L./lib

HYPRE_DIR = ./hypre
HYPRE_INCLUDE = -I$(HYPRE_DIR)/include
HYPRE_LIBPATH = -L$(HYPRE_DIR)/lib -lHYPRE -lm

OBJECTS = Datatype Read_Data Solver Result Mem_Free
##OBJECTS = Datatype Read_Data Solver Result_vis Mem_Free

all: main

./lib/lib%.so: ./src/%.c
	$(C)  $(CFLAGS)  -o $@ $< $(INCLUDE) $(HYPRE_INCLUDE) 

main: $(addsuffix .so, $(addprefix ./lib/lib, $(OBJECTS))) main.c 
	$(C) -g $(INCLUDE) $(HYPRE_INCLUDE) main.c -o $@ $(LIBPATH) $(HYPRE_LIBPATH) $(addprefix -l, $(OBJECTS)) -lstdc++ 
#	mpirun -np 2 ./main

clean:
	-rm ./lib/*.so
	-rm main
	-rm ./result/*.dat
	-rm -r html
	-rm -r main.dSYM
	-rm -r latex
